import _ from "lodash";
export default {
    data() {
        return {
            shareOps: {},
        };
    },
    onLoad() {
        // 获取小程序名称作为默认标题
        const appName = import.meta.env.VITE_APP_TITLE || "默认";
        const pages = getCurrentPages();
        let currentPage = pages[pages.length - 1];
        let currentPagePath = currentPage.route;
        let currentPageOps = currentPage.options;

        if (_.isPlainObject(currentPageOps) && !_.isEmpty(currentPageOps)) {
            currentPagePath += `?${_.map(currentPageOps, (value, key) => `${key}=${value}`).join("&")}`;
        }
        this.shareOps = {
            title: appName,
            path: currentPagePath,
            imageUrl: "",
        };
        // 禁止分享的黑名单
        const blackList = ["pages/login/index"];
        if (blackList.includes(currentPage.route)) {
            uni.hideShareMenu();
        }
    },

    // 分享给好友
    onShareAppMessage() {
        return this.shareOps;
    },

    // 分享到朋友圈
    onShareTimeline() {
        return this.share;
    },
};
